﻿using System;
using System.Text;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using AnalyseCrmMana;

namespace AnalyseCRM.InteractiveData
{
    public partial class CustomerViewAjax : System.Web.UI.Page
    {
        private string _paramValue = "", _paramType = "";
        private String _strsj = "", _strkhxm = "", _strzjhm = "", _strwhere = "";
        protected void Page_Load(object sender, EventArgs e)
        {
            if (Request["paramvalue"] != null)
            {
                _paramValue = Server.UrlDecode(Request["paramvalue"].ToString());
            }
            if (Request["paramtype"] != null)
            {
                _paramType = Request["paramtype"].ToString();
            }
            if (Request["SJ"] != null)
            {
                _strsj = Request["SJ"].ToString();
                if (_strsj != "")
                    _strwhere = " ISNULL(RELTELPHONE,'') LIKE '%" + _strsj + "%'";
            }
            if (Request["KHXM"] != null)
            {
                _strkhxm = Request["KHXM"].ToString();
                if (_strkhxm != "")
                {
                    if (_strwhere != "")
                    {
                        _strwhere = _strwhere + " |ISNULL(GUESTNAME,'')  LIKE '%" + _strkhxm + "%'";

                    }
                    else
                    {
                        _strwhere = " ISNULL(GUESTNAME,'')  LIKE '%" + _strkhxm + "%'";
                    }
                
                }
                 
            }
            if (Request["ZJHM"] != null)
            {
                _strzjhm = Request["ZJHM"].ToString();
                if (_strzjhm != "")
                {
                    if (_strwhere != "")
                   {
                       _strwhere = _strwhere + " |ISNULL(CERTIFICATENUM,'')   LIKE '%" + _strzjhm + "%'";
                   }
                   else
                   {
                       _strwhere = " ISNULL(CERTIFICATENUM,'')   LIKE '%" + _strzjhm + "%'";
                   }

                
                }
                    
            }

            if (_paramType == "GetGustomerInfoForper")
            {
                if (Request["GUESTNO"] != null)
                {

                    _strwhere =Request["GUESTNO"].ToString(); ;
                }
            
            }

            Response.Write(buildHtml(_paramValue, _paramType, _strwhere));
        }

        public StringBuilder buildHtml(string prparamValue, string prparamType, string strwhere)
        {
            StringBuilder returnValue = null;
            switch (prparamType)
            {
                #region InsertEstimationGuest
                case "GetGustomerInfo":
                    returnValue = new StringBuilder();
                    IList<CustomerViewMana> customlist = new List<CustomerViewMana>();
                    CustomerViewMana custom = new CustomerViewMana();
                    string[] para = prparamValue.Split('|');
                 //   customlist = custom.GetGustomerInfo(para);
                    if (strwhere == "")
                    {
                        customlist = custom.GetGustomerInfo(para);
                    }
                    else
                    {
                        customlist = custom.GetGustomerInfoForContion(para, strwhere);
                    }
                    int customcount = custom.GetCustomerCount("", strwhere);
                    if (customlist != null && customlist.Count > 0)
                    {
                        returnValue.Append(JsonHelper.ListToJson(customlist));
                        returnValue.Append("$" + customcount);
                    }
                    else
                    {
                        returnValue.Append("none$0");
                    }
                    break;
                #endregion 
                #region GetGustomerInfoForper
                case "GetGustomerInfoForper":
                    returnValue = new StringBuilder();
                    IList<CustomerViewMana> customlistper = new List<CustomerViewMana>();
                    CustomerViewMana customper = new CustomerViewMana();
                    string[] paraper = prparamValue.Split('|');
                    //   customlist = custom.GetGustomerInfo(para);
                    if (strwhere == "")
                    {
                        customlistper = customper.GetGustomerInfoFoPer(strwhere);
                    }
                    else
                    {
                        customlistper = customper.GetGustomerInfoFoPer(strwhere);
                    }
                //    int customcountper = customper.GetCustomerCount("", strwhere);
                    if (customlistper != null && customlistper.Count > 0)
                    {
                        returnValue.Append(JsonHelper.ListToJson(customlistper));
                      //  returnValue.Append("$" + customcountper);
                    }
                    else
                    {
                        returnValue.Append("none$0");
                    }
                    break;
                #endregion  
                #region BuilderChartF02001
                case "BuilderChartF02001":
                    string chartno = prparamValue;
                    returnValue = new StringBuilder();
                    ChartBuildMana chartbm = new ChartBuildMana().getSecChartBuild(chartno,"admin");
                    if (chartbm != null)
                    {
                        returnValue.Append(JsonHelper.ObjectToJson(chartbm));
                    }
                    else
                    {
                        returnValue.Append("NONE");
                    }
                    break;
                #endregion
                #region BuilderChartF02002
                case "BuilderChartF02002":
                    string chartno1 = prparamValue;
                    returnValue = new StringBuilder();
                    ChartBuildMana chartbm1 = new ChartBuildMana().getChartBuild(chartno1, "admin");
                    if (chartbm1 != null)
                    {
                        returnValue.Append(JsonHelper.ObjectToJson(chartbm1));
                    }
                    else
                    {
                        returnValue.Append("NONE");
                    }
                    break;
                #endregion
                #region BuilderChartF02003
                case "BuilderChartF02003":
                    string chartno2 = prparamValue;
                    returnValue = new StringBuilder();
                    ChartBuildMana chartbm2 = new ChartBuildMana().getChartBuild(chartno2, "admin");
                    if (chartbm2 != null)
                    {
                        returnValue.Append(JsonHelper.ObjectToJson(chartbm2));
                    }
                    else
                    {
                        returnValue.Append("NONE");
                    }
                    break;
                #endregion
                #region BuilderChartF02004
                case "BuilderChartF02004":
                    string chartno3 = prparamValue;
                    returnValue = new StringBuilder();
                    ChartBuildMana chartbm3 = new ChartBuildMana().getSecChartBuild(chartno3, "admin");
                    if (chartbm3 != null)
                    {
                        returnValue.Append(JsonHelper.ObjectToJson(chartbm3));
                    }
                    else
                    {
                        returnValue.Append("NONE");
                    }
                    break;
                #endregion
                #region BuilderChartF02005
                case "BuilderChartF02005":
                    string chartno4 = prparamValue;
                    returnValue = new StringBuilder();
                    ChartBuildMana chartbm4 = new ChartBuildMana().getChartBuild(chartno4, "admin");
                    if (chartbm4 != null)
                    {
                        returnValue.Append(JsonHelper.ObjectToJson(chartbm4));
                    }
                    else
                    {
                        returnValue.Append("NONE");
                    }
                    break;
                #endregion
                #region BuilderChartF02006
                case "BuilderChartF02006":
                    string chartno5 = prparamValue;
                    returnValue = new StringBuilder();
                    ChartBuildMana chartbm5 = new ChartBuildMana().getChartBuild(chartno5, "admin");
                    if (chartbm5 != null)
                    {
                        returnValue.Append(JsonHelper.ObjectToJson(chartbm5));
                    }
                    else
                    {
                        returnValue.Append("NONE");
                    }
                    break;
                #endregion
                #region BuilderChartF02007
                case "BuilderChartF02007":
                    string chartno6 = prparamValue;
                    returnValue = new StringBuilder();
                    ChartBuildMana chartbm6 = new ChartBuildMana().getChartBuild(chartno6, "admin");
                    if (chartbm6 != null)
                    {
                        returnValue.Append(JsonHelper.ObjectToJson(chartbm6));
                    }
                    else
                    {
                        returnValue.Append("NONE");
                    }
                    break;
                #endregion
                #region BuilderChartF02008
                case "BuilderChartF02008":
                    string chartno7 = prparamValue;
                    returnValue = new StringBuilder();
                    ChartBuildMana chartbm7 = new ChartBuildMana().getSecChartBuild(chartno7, "admin");
                    if (chartbm7 != null)
                    {
                        returnValue.Append(JsonHelper.ObjectToJson(chartbm7));
                    }
                    else
                    {
                        returnValue.Append("NONE");
                    }
                    break;
                #endregion
                #region BuilderChartF02010
                case "BuilderChartF02010":
                    string chartno9 = prparamValue;
                    returnValue = new StringBuilder();
                    ChartBuildMana chartbm9 = new ChartBuildMana().getChartBuild(chartno9, "admin");
                    if (chartbm9 != null)
                    {
                        returnValue.Append(JsonHelper.ObjectToJson(chartbm9));
                    }
                    else
                    {
                        returnValue.Append("NONE");
                    }
                    break;
                #endregion
                #region BuilderChartF02012
                case "BuilderChartF02012":
                    string chartno11 = prparamValue;
                    returnValue = new StringBuilder();
                    ChartBuildMana chartbm11 = new ChartBuildMana().getChartBuild(chartno11, "admin");
                    if (chartbm11 != null)
                    {
                        returnValue.Append(JsonHelper.ObjectToJson(chartbm11));
                    }
                    else
                    {
                        returnValue.Append("NONE");
                    }
                    break;
                #endregion
                #region BuilderChartF02013
                case "BuilderChartF02013":
                    string chartno12 = prparamValue;
                    returnValue = new StringBuilder();
                    ChartBuildMana chartbm12 = new ChartBuildMana().getChartBuild(chartno12, "admin");
                    if (chartbm12 != null)
                    {
                        returnValue.Append(JsonHelper.ObjectToJson(chartbm12));
                    }
                    else
                    {
                        returnValue.Append("NONE");
                    }
                    break;
                #endregion
                #region BuilderChartF02014
                case "BuilderChartF02014":
                    string chartno13 = prparamValue;
                    returnValue = new StringBuilder();
                    ChartBuildMana chartbm13 = new ChartBuildMana().getChartBuild(chartno13, "admin");
                    if (chartbm13 != null)
                    {
                        returnValue.Append(JsonHelper.ObjectToJson(chartbm13));
                    }
                    else
                    {
                        returnValue.Append("NONE");
                    }
                    break;
                #endregion
                #region BuilderChartF02015
                case "BuilderChartF02015":
                    string chartno14 = prparamValue;
                    returnValue = new StringBuilder();
                    ChartBuildMana chartbm14 = new ChartBuildMana().getChartBuild(chartno14, "admin");
                    if (chartbm14 != null)
                    {
                        returnValue.Append(JsonHelper.ObjectToJson(chartbm14));
                    }
                    else
                    {
                        returnValue.Append("NONE");
                    }
                    break;
                #endregion
          
 
                default:
                    break;
            }
            return returnValue;

        }  
    }
}